<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //   function A() {
      //     var a = 1;
      //     function B() {
      //       console.log(a++);
      //     }
      //     return B;
      //   }
      //   var f = A();
      //   f();
      //   f();

      //深拷贝
      function cloneDeep(target) {
        if (typeof target !== 'object') {
          return target;
        }
        var newObj = {};
        for (var k in target) {
          newObj[k] = target[k];
        }
        return newObj;
      }
      var obj1 = { name: 'xx' };
      var obj2 = cloneDeep(obj1);
      obj2.name = 'u';
      console.log(obj1.name);
      console.log(obj2.name);
    </script>
  </body>
</html>
